package com.tj.collection.controller.lending.response;

import com.fqgj.common.api.ResponseData;
import com.fqgj.common.utils.DateUtil;
import com.fqgj.common.utils.StringUtils;
import com.tj.collection.db.entity.ClReceiverDetailEntity;
import com.tj.collection.enums.ClSexEnum;
import com.tj.collection.enums.ClUserEducationEnum;
import com.tj.collection.enums.ClUserMarriageEnum;
import com.tj.collection.utils.DateUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: Karl
 * Date: 2020/12/22 4:22 下午
 */
public class ClUserBaseInfoResponse implements ResponseData {

    private List<Item> list = new ArrayList<>();

    public ClUserBaseInfoResponse(ClReceiverDetailEntity clReceiverDetailEntity) {
        Item item = null;
        item = new Item().setName("Name").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getName()) ? clReceiverDetailEntity.getName() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Mobile").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getMobile()) ? clReceiverDetailEntity.getMobile() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Email").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getEmail()) ? clReceiverDetailEntity.getEmail() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("PAN").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getPanCardNo()) ? clReceiverDetailEntity.getPanCardNo() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Aadhaar").setValue(clReceiverDetailEntity.getAadhaarNo() != null ? clReceiverDetailEntity.getAadhaarNo() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Current City").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getCity()) ? clReceiverDetailEntity.getCity() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Address").setValue(StringUtils.isNotEmpty(clReceiverDetailEntity.getAddress()) ? clReceiverDetailEntity.getAddress() : "--").setFlag("information");
        list.add(item);
        item = new Item().setName("Age").setValue(clReceiverDetailEntity.getBirthday() != null ? DateUtils.getAgeByBirth(DateUtil.getDate(clReceiverDetailEntity.getBirthday(), "yyyy-MM-dd")) + "" : "--").setFlag("information");
        list.add(item);

        item = new Item().setName("Name").setValue(strConvert(clReceiverDetailEntity.getName())).setFlag("basic");
        list.add(item);
        ClSexEnum clSexEnum = ClSexEnum.getEnum(clReceiverDetailEntity.getSex());
        item = new Item().setName("Gender").setValue(clSexEnum != null ? clSexEnum.getDesc() : "--").setFlag("basic");
        list.add(item);
        item = new Item().setName("Date of Birth").setValue(strConvert(clReceiverDetailEntity.getBirthday())).setFlag("basic");
        list.add(item);

        ClUserMarriageEnum clUserMarriageEnum = ClUserMarriageEnum.getEnum(clReceiverDetailEntity.getMarriedStatus());
        item = new Item().setName("Marital Status").setValue(clUserMarriageEnum != null ? clUserMarriageEnum.getDesc() : "--").setFlag("basic");
        list.add(item);

        ClUserEducationEnum clUserEducationEnum = ClUserEducationEnum.getEnum(clReceiverDetailEntity.getEducation());
        item = new Item().setName("Education").setValue(clUserEducationEnum != null ? clUserEducationEnum.getDesc() : "--").setFlag("basic");
        list.add(item);

        // 地址信息
        item = new Item().setName("State").setValue(strConvert(clReceiverDetailEntity.getProvince())).setFlag("basic");
        list.add(item);
        item = new Item().setName("City").setValue(strConvert(clReceiverDetailEntity.getCity())).setFlag("basic");
        list.add(item);
        item = new Item().setName("Address").setValue(strConvert(clReceiverDetailEntity.getAddress())).setFlag("basic");
        list.add(item);
        item = new Item().setName("PinCode").setValue(strConvert(clReceiverDetailEntity.getPinCode())).setFlag("basic");
        list.add(item);
    }

    public List<Item> getList() {
        return list;
    }

    public ClUserBaseInfoResponse setList(List<Item> list) {
        this.list = list;
        return this;
    }

    private String strConvert(String str) {
        if (StringUtils.isEmpty(str)) {
            return "--";
        }
        return str;
    }

    private class Item {
        private String name;
        private String value;
        private String flag;

        public String getName() {
            return name;
        }

        public Item setName(String name) {
            this.name = name;
            return this;
        }

        public String getValue() {
            return value;
        }

        public String getFlag() {
            return flag;
        }

        public Item setFlag(String flag) {
            this.flag = flag;
            return this;
        }

        public Item setValue(String value) {
            if (StringUtils.isEmpty(value)) {
                value = "--";
            }

            this.value = value.replace("null", "--");
            return this;
        }
    }


}
